package com.googlecode.quillen.util;

import org.apache.commons.logging.Log;

/**
 * Created by IntelliJ IDEA.
 * User: greg
 * Date: Dec 15, 2008
 * Time: 1:07:43 PM
 */
public class Utils
{
    public static void logInfo(Log log, String msg, Object... args)
    {
        String message = String.format(msg, args);

        System.err.printf("INFO: " + message + "\n", args);

        if (log.isInfoEnabled())
        {
//            log.info(message);
        }
    }

    public static void logDebug(Log log, String msg, Object... args)
    {
//        System.err.printf("DEBUG: " + msg + "\n", args);
        
        if (log.isDebugEnabled())
        {
//            log.debug(String.format(msg, args));
        }
    }

    public static void logWarning(Log log, String msg, Object... args)
    {
        System.err.printf("WARNING: " + msg + "\n", args);

        if (log.isWarnEnabled())
        {
//            log.warn(String.format(msg, args));
        }
    }

    public static <T> void logError(Log log, Throwable t, ResultConsumer<T> consumer, String msg, Object... args)
    {
        String message = String.format(msg, args);

        if (log.isErrorEnabled())
        {
            log.error(message, t);
        }

        if (consumer != null)
        {
            consumer.newError(message, t);
        }
    }
}
